﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml.Serialization;

namespace Etest.Models
{

    [XmlRoot(ElementName = "access", Namespace = "http://docs.openstack.org/identity/api/v2.0")]
    public class Access
    {
        [XmlElement("token")]
        public Token token { get; set; }

        [XmlArray("serviceCatalog")]
        [XmlArrayItem("service", typeof(Service))]
        public List<Service> services { get; set; }

        [XmlElement("user")]
        public User user { get; set; }

        [XmlElement("metadata")]
        public MetaData metadata { get; set; }
    }

    
    public class Tenant
    {
        [XmlAttribute("id")]
        public string id { get; set; }

        [XmlAttribute("name")]
        public string name { get; set; }

        [XmlAttribute("enabled")]
        public string enabled { get; set; }
    }

    
    public class Token
    {
        [XmlAttribute("id")]
        public string id { get; set; }

        [XmlAttribute("expires")]
        public string expires { get; set; }

        [XmlAttribute("issued_at")]
        public string issued_at { get; set; } // moze i DateTime2

        [XmlElement("tenant")]
        public Tenant tenant { get; set; }
    }

  
    public class Service
    {
        [XmlAttribute("name")]
        public string name { get; set; }

        [XmlAttribute("type")]
        public string type { get; set; }

        [XmlElement("endpoint")]
        public Endpoint endpoint { get; set; }

    }

    
    public class Endpoint
    {
        [XmlAttribute("id")]
        public string id { get; set; }

        [XmlAttribute("internalURL")]
        public string internalURL { get; set; }

        [XmlAttribute("publicURL")]
        public string publicURL { get; set; }

        [XmlAttribute("region")]
        public string region { get; set; }

        [XmlAttribute("adminURL")]
        public string adminURL { get; set; }
    }
   
    public class User
    {
        [XmlAttribute("id")]
        public string id { get; set; }

        [XmlAttribute("name")]
        public string name { get; set; }

        [XmlAttribute("username")]
        public string username { get; set; }

        [XmlElement("role")]
        public Role role { get; set; }
    }

   
   // [XmlElement(IsNullable = true)]
    public class Role
    {
        [XmlAttribute("name")]
        public string name { get; set; }
    }

    public class MetaData
    {

        [XmlAttribute("is_admin")]
        public string is_admin { get; set; }

        [XmlElement("role")]
        public Role role { get; set; }
    }

    public class ImageGroup
    {
        public LinkedList<Image> images { get; set; }
    }

    public class Image
    {
        public string id { get; set; }
        public string name { get; set; }
        public LinkedList<Link> links { get; set; }
    }

    public class Link
    {
        public string href { get; set; }
        public string type { get; set; }
        public string rel { get; set; }
    }

    public class Flavor
    {
        public string id { get; set; }
        public string name { get; set; }
        public LinkedList<Link> links { get; set; }
    }

    public class FlavorGroup
    {
        public LinkedList<Flavor> flavors { get; set; }
    }

    //podeli gi po namespace

    public class Server
    {
        [JsonProperty(PropertyName="server")]
        public ServerInfo serverInfo { get; set; }
    }
    public class ServerInfo
    {
        
        public List<SecurityGroup> security_groups { get; set; }
        
        [JsonProperty(PropertyName = "OS-DCF:diskConfig")]
        public string OS_DCF_diskConfig { get; set; }

        public string id { get; set; }
        public List<Link> links { get; set; }
        public string adminPass { get; set; } 

    }

    public class SecurityGroup
    {
        public string name { get; set; }
    }

    public class Addresses
    {
        [JsonProperty(PropertyName="addresses")]
        public AddressesInfo addressesInfo { get; set; } 
    }
    
    public class AddressesInfo
    {
        [JsonProperty(PropertyName = "public")]
        public List<Address> publicAddress { get; set; }

        [JsonProperty(PropertyName = "private")]
        public List<Address> privateAddress { get; set; }
    }
    public class Address
    {
        public string version { get; set; }
        public string addr { get; set; }
    }

    public class BulkFloatingIp
    {
        public List<IpInfo> floating_ip_info { get; set; }
    }

    public class IpInfo
    {
    
        [JsonProperty(PropertyName="interface")]
        public string interface_ { get; set; }
        public string instance_uuid { get; set; }
        public string project_id { get; set; }
        public string pool { get; set; }
        public string address { get; set; }
        
    }

    public class ServerStatus
    {
        [JsonProperty(PropertyName = "server")]
        public Status server;
    }

    public class Status
    {
        public string status { get; set; }
    }

}